package networkInterface;

import java.awt.Color;

import object.Node;

public class Phone3GInterface extends PhoneInterfaceBase {

	public Phone3GInterface(Node node) {
		super(node, Color.ORANGE);
		range = 800;
	}

	@Override
	public String canConnectWithReason(NetworkInterfaceBase netInt) {
		if(!(netInt instanceof Tower3GInterface))
			return "not a Tower3GInterface";
	
		if(this.getNode()==null)
			return "Interface doesn't have node";
		
		if(this.isDirectlyConnected(netInt) || netInt.isDirectlyConnected(this))
			return "Already connected on this interface";
		
		if(this.getNode().isDirectlyConnected(netInt.getNode()) || netInt.getNode().isDirectlyConnected(this.getNode()))
			return "Nodes already connected on other interface";
		
		if(this.getNode()==netInt.getNode())
			return "Can't connect to interfaces on same node";
		
		if(this.getNode().getLength(netInt.getNode()) > range || netInt.getNode().getLength(this.getNode()) > ((PhoneInterfaceBase)netInt).getRange())
			return "Out of Range";
		
		if(!(this.hasConnectionsAvailible() && netInt.hasConnectionsAvailible()))
			return "No connections left";

		return null;
	}
	
	@Override
	public boolean hasConnectionsAvailible(){
		if(node==null)
			return false;
		if(connections.size() < 1)
			return true;
		return false;
	}
}
